package fr.web325.servlet.api.user;


import fr.web325.bean.Json;
import net.sf.json.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/api/user")
public class User extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取用户信息
        HttpSession session = req.getSession();
        if(session.getAttribute("user") == null){
            resp.getWriter().print(new Json(200,null,"请登陆后重试").getRespJson());
        }else{
            fr.web325.bean.User user =(fr.web325.bean.User) session.getAttribute("user");
            JSONObject userObj = JSONObject.fromObject(user);
            resp.getWriter().print(new Json(200,userObj,"获取用户信息成功!").getRespJson());
        }
    }
}
